import QtQuick 2.6
import Qt.labs.controls 1.0
import QtQuick.Layouts 1.3

Popup {
    id: pop
    modal: true
    focus: true
    closePolicy: Popup.NoAutoClose
    default property alias  content: page.contentItem
    property alias title: labelTitle.text
    topPadding:1
    leftPadding: 1
    rightPadding: 1
    bottomPadding: 1
    contentWidth: contentArea.availableWidth - 24
    x : contentArea.availableWidth / 2 - contentWidth / 2
    y: contentArea.availableHeight / 2 - contentHeight / 2

    property string btnCancelText : "取消"
    property string btnOkText: "确定"
    signal clicked()
    signal closed()
    property alias footer: page.footer

    Page {
        anchors.fill: parent
        leftPadding: 9
        rightPadding: 9

        id: page
        header:  ToolBar {
            leftPadding: 9
            rightPadding: 1

            RowLayout {
                anchors.fill: parent

                Label {
                    id: labelTitle
                    font.pixelSize: 15
                    verticalAlignment: Text.AlignVCenter
                    Layout.fillWidth: true
                }

                ToolButton {
                    text: "close"
                    Layout.alignment: Qt.AlignRight
                    label: Image {
                        source: "../images/close.png"
                        anchors.centerIn: parent
                        opacity: 0.6
                    }
                    onClicked: pop.close()
                }
            }
        }

        footer:  ToolBar{
            leftPadding: 1
            rightPadding: 1
            bottomPadding: 1
            Row {anchors.fill: parent
                Button {
                    text: btnCancelText
                    width: parent.width /2
                    onClicked: { pop.close(); pop.closed() }
                }

                Button {
                    text: btnOkText
                    onClicked: { pop.close(); pop.clicked() }
                    width: parent.width /2
                }
            }
        }
    }
}

